<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>皮肤</title>
    <style>
        #divblock {
            width: 500px;
            height: 500px;
            background-color: #000000;
            margin-top: 10px;
        }
    </style>
    <script>
        function $ (id) {
            return document.getElementById(id);
        }

        function redSet () {
            let value = '#ff0000';
            $('divblock').style.backgroundColor = value;
            window.localStorage.setItem('divBackGroundColor', value);
        }

        function greenSet () {
            let value = '#00ff00';
            $('divblock').style.backgroundColor = value;
            window.localStorage.setItem('divBackGroundColor', value);
        }

        function blueSet () {
            let value = '#0000ff';
            $('divblock').style.backgroundColor = value;
            window.localStorage.setItem('divBackGroundColor', value);
        }

        function colorload () {
            let backColor = window.localStorage.getItem('divBackGroundColor');
            if (backColor) {
                $('divblock').style.backgroundColor = backColor;
                console.log(`backColor: ${backColor}`);
            } else {
                console.log('还没有设置divBackGroundColor');
            }
        }

        window.onload = function () {
            colorload();
        }
    </script>
</head>
<body>
    <section>
        <button onclick="redSet()" id="redbutton">红色</button>
        <button onclick="greenSet()" id="greenbutton">绿色</button>
        <button onclick="blueSet()" id="bluebutton">蓝色</button>
        <div id="divblock"></div>
    </section>
</body>
</html>